package GUI;

import DTOs.IdiomaDTO;
import Exepciones.ExcepcionConexionError;
import Exepciones.ExcepcionDataBaseError;
import controladores.ControladorTraductorExterno;
import controladores.ControladorTraductorInterno;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeSet;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import persistencia.DAOFactory;
import servicioTraductores.AdministradorServicio;
import servicioTraductores.Servicio;

/**
 * Der Hund
 *
 */
public class JFrameMain extends javax.swing.JFrame {

    DefaultComboBoxModel modelDB;
    DefaultComboBoxModel modelServicios;
    DefaultComboBoxModel modelIdiomasOrigen;
    DefaultComboBoxModel modelIdiomasDestino;
    DefaultComboBoxModel modelListaResultados;
    AdministradorServicio admServicio = AdministradorServicio.getInstancia();
    Map<String, Servicio> servicios = admServicio.getServicios();
    ArrayList<DAOFactory> factorias = DAOFactory.getFactorys();
    Servicio unServicio;
    private DAOFactory selectedFactory;
    private String idServicio;
    private String textoOrigen;
    private String idiomaOrig;
    private String textoDestExt;
    private String idiomaDest;
    private String textoDestInt;
    private boolean eliminar = false;
    //Colores para los textos traducidos.
    private String colorVerde = "#00FF00";
    private String colorAzul = "#0000FF";
    //Fuente de texto
    private String fuenteTextos = "Andale Mono";
    private int estiloTextos = 0;
    private int tamTextos = 13;

    public JFrameMain() {
        this.initComponents();
        this.setImagenes();
        this.initComboBox();
        //jTextAreaDestinoExt.setEditable(false);// PONER EN FALSE AL MOMENTO DE LA ENTREGA.
        this.setDefaultComponentes();

        this.setFuente(fuenteTextos, estiloTextos, tamTextos);

        System.out.println("#################################\n  INICIO DEL TRADUCTOR DER HUND \n#################################");
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrameCaratula = new javax.swing.JFrame();
        jPanelCaratula = new javax.swing.JPanel();
        jLabelCaratula = new javax.swing.JLabel();
        jFrameVerTexto = new javax.swing.JFrame();
        jScrollPane8 = new javax.swing.JScrollPane();
        jTextAreaVerTexto = new javax.swing.JTextArea();
        jButtonActualizarVerTexto = new javax.swing.JButton();
        jButtonCerrarVerTexto = new javax.swing.JButton();
        jDialogEliminar = new javax.swing.JDialog();
        jLabelEliminar = new javax.swing.JLabel();
        jButtonAceptar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jComboBoxServicio = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaOrigen = new javax.swing.JTextArea();
        jComboBoxIdiomaOrigen = new javax.swing.JComboBox();
        jComboBoxIdiomaDestino = new javax.swing.JComboBox();
        jButtonTraducir = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaDestinoExt = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jListDestinoInt = new javax.swing.JList();
        jButtonActualizar = new javax.swing.JButton();
        jButtonAgregar = new javax.swing.JButton();
        jButtonVerTexto = new javax.swing.JButton();
        jButtonCambio = new javax.swing.JButton();
        jLabelTraductor = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jComboBoxDB = new javax.swing.JComboBox();
        jLabelDB = new javax.swing.JLabel();
        jLabelMensajes = new javax.swing.JLabel();
        jButtonEliminar = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenuArchivo = new javax.swing.JMenu();
        jMenuItemSalir = new javax.swing.JMenuItem();
        jMenuAyuda = new javax.swing.JMenu();
        jMenuItemAcercaDe = new javax.swing.JMenuItem();

        jFrameCaratula.setName("jFrameCaratula"); // NOI18N

        jPanelCaratula.setName("jPanelCaratula"); // NOI18N

        jLabelCaratula.setName("jLabelCaratula"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanelCaratulaLayout = new org.jdesktop.layout.GroupLayout(jPanelCaratula);
        jPanelCaratula.setLayout(jPanelCaratulaLayout);
        jPanelCaratulaLayout.setHorizontalGroup(
            jPanelCaratulaLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelCaratulaLayout.createSequentialGroup()
                .add(jLabelCaratula)
                .addContainerGap(455, Short.MAX_VALUE))
        );
        jPanelCaratulaLayout.setVerticalGroup(
            jPanelCaratulaLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelCaratulaLayout.createSequentialGroup()
                .add(jLabelCaratula)
                .addContainerGap(301, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jFrameCaratulaLayout = new org.jdesktop.layout.GroupLayout(jFrameCaratula.getContentPane());
        jFrameCaratula.getContentPane().setLayout(jFrameCaratulaLayout);
        jFrameCaratulaLayout.setHorizontalGroup(
            jFrameCaratulaLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelCaratula, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jFrameCaratulaLayout.setVerticalGroup(
            jFrameCaratulaLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelCaratula, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jFrameVerTexto.setName("jFrameVerTexto"); // NOI18N

        jScrollPane8.setName("jScrollPane8"); // NOI18N

        jTextAreaVerTexto.setColumns(20);
        jTextAreaVerTexto.setRows(5);
        jTextAreaVerTexto.setName("jTextAreaVerTexto"); // NOI18N
        jScrollPane8.setViewportView(jTextAreaVerTexto);

        jButtonActualizarVerTexto.setText("Actualizar");
        jButtonActualizarVerTexto.setName("jButtonActualizarVerTexto"); // NOI18N
        jButtonActualizarVerTexto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonActualizarVerTextoActionPerformed(evt);
            }
        });

        jButtonCerrarVerTexto.setText("Cerrar");
        jButtonCerrarVerTexto.setName("jButtonCerrarVerTexto"); // NOI18N
        jButtonCerrarVerTexto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCerrarVerTextoActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jFrameVerTextoLayout = new org.jdesktop.layout.GroupLayout(jFrameVerTexto.getContentPane());
        jFrameVerTexto.getContentPane().setLayout(jFrameVerTextoLayout);
        jFrameVerTextoLayout.setHorizontalGroup(
            jFrameVerTextoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jFrameVerTextoLayout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 380, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jFrameVerTextoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(jButtonCerrarVerTexto, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jButtonActualizarVerTexto))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jFrameVerTextoLayout.setVerticalGroup(
            jFrameVerTextoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jFrameVerTextoLayout.createSequentialGroup()
                .addContainerGap()
                .add(jFrameVerTextoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 265, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jFrameVerTextoLayout.createSequentialGroup()
                        .add(36, 36, 36)
                        .add(jButtonActualizarVerTexto)
                        .add(18, 18, 18)
                        .add(jButtonCerrarVerTexto)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jDialogEliminar.setName("jDialogEliminar"); // NOI18N

        jLabelEliminar.setText("¿Desea eliminar la traducion?");
        jLabelEliminar.setName("jLabelEliminar"); // NOI18N

        jButtonAceptar.setText("Aceptar");
        jButtonAceptar.setName("jButtonAceptar"); // NOI18N
        jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAceptarActionPerformed(evt);
            }
        });

        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.setName("jButtonCancelar"); // NOI18N
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jDialogEliminarLayout = new org.jdesktop.layout.GroupLayout(jDialogEliminar.getContentPane());
        jDialogEliminar.getContentPane().setLayout(jDialogEliminarLayout);
        jDialogEliminarLayout.setHorizontalGroup(
            jDialogEliminarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jDialogEliminarLayout.createSequentialGroup()
                .add(79, 79, 79)
                .add(jDialogEliminarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jDialogEliminarLayout.createSequentialGroup()
                        .add(jButtonCancelar)
                        .add(18, 18, 18)
                        .add(jButtonAceptar))
                    .add(jLabelEliminar))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        jDialogEliminarLayout.setVerticalGroup(
            jDialogEliminarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jDialogEliminarLayout.createSequentialGroup()
                .add(38, 38, 38)
                .add(jLabelEliminar)
                .add(33, 33, 33)
                .add(jDialogEliminarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonCancelar)
                    .add(jButtonAceptar))
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setName("jPanel1"); // NOI18N

        jComboBoxServicio.setToolTipText("Seleccione servicio externo.");
        jComboBoxServicio.setName("jComboBoxServicio"); // NOI18N
        jComboBoxServicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxServicioActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextAreaOrigen.setColumns(20);
        jTextAreaOrigen.setRows(5);
        jTextAreaOrigen.setToolTipText("Presione Control para traducir y Alt para cambiar idioma.");
        jTextAreaOrigen.setWrapStyleWord(true);
        jTextAreaOrigen.setName("jTextAreaOrigen"); // NOI18N
        jTextAreaOrigen.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTextAreaOrigenPropertyChange(evt);
            }
        });
        jTextAreaOrigen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextAreaOrigenKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextAreaOrigenKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTextAreaOrigen);

        jComboBoxIdiomaOrigen.setToolTipText("Seleccione idioma origen.");
        jComboBoxIdiomaOrigen.setName("jComboBoxIdiomaOrigen"); // NOI18N
        jComboBoxIdiomaOrigen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxIdiomaOrigenActionPerformed(evt);
            }
        });

        jComboBoxIdiomaDestino.setToolTipText("Seleccione idioma destino.");
        jComboBoxIdiomaDestino.setName("jComboBoxIdiomaDestino"); // NOI18N
        jComboBoxIdiomaDestino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxIdiomaDestinoActionPerformed(evt);
            }
        });
        jComboBoxIdiomaDestino.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jComboBoxIdiomaDestinoMouseReleased(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jComboBoxIdiomaDestinoMouseExited(evt);
            }
        });

        jButtonTraducir.setText("Traducir");
        jButtonTraducir.setToolTipText("Traducir texto.");
        jButtonTraducir.setName("jButtonTraducir"); // NOI18N
        jButtonTraducir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTraducirActionPerformed(evt);
            }
        });

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTextAreaDestinoExt.setColumns(20);
        jTextAreaDestinoExt.setRows(5);
        jTextAreaDestinoExt.setToolTipText("Resultado servicio externo.");
        jTextAreaDestinoExt.setName("jTextAreaDestinoExt"); // NOI18N
        jScrollPane2.setViewportView(jTextAreaDestinoExt);

        jLabel2.setText("Resultado Externo");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText("Resultado Interno");
        jLabel3.setName("jLabel3"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jListDestinoInt.setFont(new java.awt.Font("Lucida Grande", 0, 13));
        jListDestinoInt.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jListDestinoInt.setToolTipText("Presione Enter o Control para traducir.");
        jListDestinoInt.setName("jListDestinoInt"); // NOI18N
        jListDestinoInt.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                jListDestinoIntMouseMoved(evt);
            }
        });
        jListDestinoInt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jListDestinoIntKeyPressed(evt);
            }
        });
        jListDestinoInt.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListDestinoIntMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jListDestinoInt);

        jButtonActualizar.setText("Actualizar");
        jButtonActualizar.setToolTipText("Actualizar selección.");
        jButtonActualizar.setName("jButtonActualizar"); // NOI18N
        jButtonActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonActualizarActionPerformed(evt);
            }
        });

        jButtonAgregar.setText("Agregar");
        jButtonAgregar.setToolTipText("Guardar nueva traducción.");
        jButtonAgregar.setName("jButtonAgregar"); // NOI18N
        jButtonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAgregarActionPerformed(evt);
            }
        });

        jButtonVerTexto.setText("Ver");
        jButtonVerTexto.setToolTipText("Ver selección.");
        jButtonVerTexto.setName("jButtonVerTexto"); // NOI18N
        jButtonVerTexto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVerTextoActionPerformed(evt);
            }
        });

        jButtonCambio.setName("jButtonCambio"); // NOI18N
        jButtonCambio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCambioActionPerformed(evt);
            }
        });

        jLabelTraductor.setText("Servicio");
        jLabelTraductor.setName("jLabelTraductor"); // NOI18N

        jLabel10.setText("Texto Origen");
        jLabel10.setName("jLabel10"); // NOI18N

        jComboBoxDB.setToolTipText("Seleccione servicio interno.");
        jComboBoxDB.setName("jComboBoxDB"); // NOI18N
        jComboBoxDB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxDBActionPerformed(evt);
            }
        });

        jLabelDB.setText("DB");
        jLabelDB.setName("jLabelDB"); // NOI18N

        jLabelMensajes.setName("jLabelMensajes"); // NOI18N

        jButtonEliminar.setText("Eliminar");
        jButtonEliminar.setToolTipText("Eliminar selección.");
        jButtonEliminar.setName("jButtonEliminar"); // NOI18N
        jButtonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel3)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(jScrollPane3)
                                    .add(jScrollPane2)
                                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE))
                                .add(18, 18, 18)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(jComboBoxIdiomaOrigen, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(jComboBoxIdiomaDestino, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                                            .add(jButtonCambio, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(18, 18, 18)
                                            .add(jButtonTraducir)
                                            .add(10, 10, 10)))
                                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                                        .add(jButtonActualizar)
                                        .add(jButtonVerTexto))
                                    .add(jButtonAgregar)
                                    .add(jButtonEliminar)))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jLabel10)
                                .add(123, 123, 123)
                                .add(jLabelDB)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(jComboBoxDB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(42, 42, 42)
                                .add(jLabelTraductor)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jComboBoxServicio, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jLabel2)))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(157, 157, 157)
                        .add(jLabelMensajes)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jButtonEliminar)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(24, 24, 24)
                                .add(jLabel10))
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(jLabelTraductor)
                                .add(jComboBoxServicio, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jComboBoxDB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabelDB)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jComboBoxIdiomaOrigen, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(jButtonCambio, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 45, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jButtonTraducir))
                                .add(9, 9, 9)
                                .add(jComboBoxIdiomaDestino, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(4, 4, 4)
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jButtonAgregar))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jLabel3)
                        .add(2, 2, 2)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jButtonActualizar)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jButtonVerTexto))
                            .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabelMensajes)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        jMenuArchivo.setText("Der Hund");
        jMenuArchivo.setName("jMenuArchivo"); // NOI18N

        jMenuItemSalir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemSalir.setText("Salir");
        jMenuItemSalir.setName("jMenuItemSalir"); // NOI18N
        jMenuItemSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSalirActionPerformed(evt);
            }
        });
        jMenuArchivo.add(jMenuItemSalir);

        jMenuBar1.add(jMenuArchivo);

        jMenuAyuda.setText("Ayuda");
        jMenuAyuda.setName("jMenuAyuda"); // NOI18N

        jMenuItemAcercaDe.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemAcercaDe.setText("Acerca de Der Hund");
        jMenuItemAcercaDe.setName("jMenuItemAcercaDe"); // NOI18N
        jMenuItemAcercaDe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemAcercaDeActionPerformed(evt);
            }
        });
        jMenuAyuda.add(jMenuItemAcercaDe);

        jMenuBar1.add(jMenuAyuda);

        setJMenuBar(jMenuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCambioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCambioActionPerformed
        Object itemOrigen = jComboBoxIdiomaOrigen.getSelectedItem();
        Object itemDestino = jComboBoxIdiomaDestino.getSelectedItem();
        jComboBoxIdiomaOrigen.setSelectedItem(itemDestino);
        jComboBoxIdiomaDestino.setSelectedItem(itemOrigen);
        this.limpiarElementos();
    }//GEN-LAST:event_jButtonCambioActionPerformed

    private void jMenuItemSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSalirActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItemSalirActionPerformed

    private void jButtonTraducirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTraducirActionPerformed
        this.actualizarValores();
        this.limpiarElementos();
        if (textoOrigen.trim().equals("")) {
            this.mostrarError("Ingrese palabras para traducir.");
            return;
        } else {
            try {
                String textoDestinoExt;
                textoDestinoExt = ControladorTraductorExterno.traducir(idServicio, textoOrigen, idiomaOrig, idiomaDest);
                jTextAreaDestinoExt.setText(textoDestinoExt);
            } catch (ExcepcionConexionError ex) {
                this.mostrarError(ex.getMessage());
                jTextAreaDestinoExt.setBackground(Color.lightGray);
            }
            ArrayList<String> listaTraducc = new ArrayList<String>();
            ArrayList<String> listaModel = new ArrayList<String>();
            try {
                listaTraducc = ControladorTraductorInterno.traducir(selectedFactory, textoOrigen, idiomaOrig, idiomaDest);
                listaTraducc = this.colorTexto(listaTraducc, colorVerde);
                listaModel.addAll(listaTraducc);
            } catch (ExcepcionConexionError ex) {
                this.mostrarError(ex.getMessage());
            } catch (Exception ex) {
                this.mostrarError(ex.getMessage());
            }
            ArrayList<String> listaSubTraducc = new ArrayList<String>();
            try {
                listaSubTraducc = ControladorTraductorInterno.traducirPorAproximacion(selectedFactory, textoOrigen, idiomaOrig, idiomaDest);
                listaSubTraducc = this.colorTexto(listaSubTraducc, colorAzul);
                listaModel.addAll(listaSubTraducc);
            } catch (ExcepcionConexionError ex) {
                this.mostrarError(ex.getMessage());
            } catch (Exception ex) {
                this.mostrarError(ex.getMessage());
            } finally {
                modelListaResultados = new DefaultComboBoxModel(listaModel.toArray());
                jListDestinoInt.setModel(modelListaResultados);
            }
        }
    }//GEN-LAST:event_jButtonTraducirActionPerformed

    private void jComboBoxIdiomaOrigenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxIdiomaOrigenActionPerformed
        this.limpiarElementos();
    }//GEN-LAST:event_jComboBoxIdiomaOrigenActionPerformed

    private void jButtonVerTextoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVerTextoActionPerformed
        if (jListDestinoInt.isSelectionEmpty()) {
            this.mostrarError("Seleccione un elemento de la lista para visualizar.");
            return;
        } else {
            this.actualizarValores();
            String txt = textoDestInt;
            jFrameVerTexto.setVisible(true);
            jTextAreaVerTexto.setText(txt);
        }
    }//GEN-LAST:event_jButtonVerTextoActionPerformed

    private void jComboBoxServicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxServicioActionPerformed
        idServicio = jComboBoxServicio.getSelectedItem().toString();
        unServicio = servicios.get(idServicio);

        final Map<String, IdiomaDTO> idiomas = unServicio.getIdiomas();
        TreeSet<String> valuesIdiomas = new TreeSet<String>(idiomas.keySet());

        modelIdiomasOrigen = new DefaultComboBoxModel(valuesIdiomas.toArray());
        modelIdiomasDestino = new DefaultComboBoxModel(valuesIdiomas.toArray());
        jComboBoxIdiomaOrigen.setModel(modelIdiomasOrigen);
        jComboBoxIdiomaDestino.setModel(modelIdiomasDestino);
        this.limpiarElementos();
    }//GEN-LAST:event_jComboBoxServicioActionPerformed

    private void jComboBoxIdiomaDestinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxIdiomaDestinoActionPerformed
        this.limpiarElementos();
    }//GEN-LAST:event_jComboBoxIdiomaDestinoActionPerformed

    private void jComboBoxIdiomaDestinoMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBoxIdiomaDestinoMouseReleased
    }//GEN-LAST:event_jComboBoxIdiomaDestinoMouseReleased

    private void jComboBoxIdiomaDestinoMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBoxIdiomaDestinoMouseExited
    }//GEN-LAST:event_jComboBoxIdiomaDestinoMouseExited

    private void jButtonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAgregarActionPerformed
        this.actualizarValores();
        if (textoOrigen.trim().equals("") || idiomaOrig.trim().equals("") || textoDestExt.trim().equals("") || idiomaDest.trim().equals("")) {
            this.mostrarError("No hay traducciones para agregar.");
            return;
        } else {
            try {
                ControladorTraductorInterno.insertar(selectedFactory, textoOrigen, idiomaOrig, textoDestExt, idiomaDest);
                this.jButtonTraducirActionPerformed(evt);
                this.mostrarExito("Traducción guardada correctamente.");
            } catch (ExcepcionConexionError ex) {
                this.mostrarError(ex.getMessage());
            } catch (ExcepcionDataBaseError ex) {
                this.mostrarError(ex.getMessage());
            }
        }
    }//GEN-LAST:event_jButtonAgregarActionPerformed

    private void jComboBoxDBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxDBActionPerformed
        this.limpiarElementos();
    }//GEN-LAST:event_jComboBoxDBActionPerformed

    private void jMenuItemAcercaDeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAcercaDeActionPerformed
        jFrameCaratula.setVisible(true);
    }//GEN-LAST:event_jMenuItemAcercaDeActionPerformed

    private void jButtonActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonActualizarActionPerformed
        this.actualizarValores();
        if (textoDestExt.trim().equals("")) {
            this.mostrarError("No existe texto para actualizar.");
            return;
        }
        if (jListDestinoInt.isSelectionEmpty()) {
            this.mostrarError("Seleccione un elemento de la lista para actualizar.");
            return;
        } else {
            try {
                String textoDestinoNew = textoDestExt;
                String textoDestinoOld = textoDestInt;
                ControladorTraductorInterno.modificar(selectedFactory, textoOrigen, idiomaOrig, textoDestinoNew, textoDestinoOld, idiomaDest);
                this.jButtonTraducirActionPerformed(evt);
                this.mostrarExito("Traducción modificada correctamente.");
            } catch (ExcepcionConexionError ex) {
                this.mostrarError(ex.getMessage());
            } catch (ExcepcionDataBaseError ex) {
                this.mostrarError(ex.getMessage());
            }
        }
    }//GEN-LAST:event_jButtonActualizarActionPerformed

    private void jListDestinoIntMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListDestinoIntMouseMoved
    }//GEN-LAST:event_jListDestinoIntMouseMoved

    private void jListDestinoIntMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListDestinoIntMouseClicked
    }//GEN-LAST:event_jListDestinoIntMouseClicked

    private void jTextAreaOrigenPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jTextAreaOrigenPropertyChange
    }//GEN-LAST:event_jTextAreaOrigenPropertyChange

    private void jListDestinoIntKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jListDestinoIntKeyPressed
        if (jListDestinoInt.isSelectionEmpty()) {
            Toolkit.getDefaultToolkit().beep();
            return;
        } else {
            if (evt.isControlDown() || evt.getKeyChar() == KeyEvent.VK_ENTER) {
                this.actualizarValores();
                String texto = textoDestInt;
                jTextAreaOrigen.setText(texto);
                this.jButtonCambioActionPerformed((ActionEvent) jButtonCambio.getAction());
                this.jButtonTraducirActionPerformed((ActionEvent) jButtonTraducir.getAction());
            }
        }
    }//GEN-LAST:event_jListDestinoIntKeyPressed

    private void jTextAreaOrigenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextAreaOrigenKeyPressed
        int a = KeyEvent.VK_CONTROL;
        if (evt.getKeyCode() == a) {
            String texto = jTextAreaOrigen.getText();
            this.jButtonTraducirActionPerformed((ActionEvent) jButtonTraducir.getAction());
            jTextAreaOrigen.setText(texto);
        }
        int b = KeyEvent.VK_ALT;
        if (evt.getKeyCode() == b) {
            this.jButtonCambioActionPerformed((ActionEvent) jButtonCambio.getAction());
        }
    }//GEN-LAST:event_jTextAreaOrigenKeyPressed
    /**
     * Comprueba que el texto de origen no se modifique.
     */
    private void jTextAreaOrigenKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextAreaOrigenKeyTyped
        String textoViejo = textoOrigen;
        this.actualizarValores();
        String textoActual = textoOrigen;
        if (textoViejo != textoActual) {//.equalsIgnoreCase() no funciona porque en ocaciones el String es NULL
            this.limpiarElementos();
        }
    }//GEN-LAST:event_jTextAreaOrigenKeyTyped

    private void jButtonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEliminarActionPerformed
        // TODO add your handling code here:
        this.actualizarValores();
        if (textoOrigen.trim().equals("") || idiomaOrig.trim().equals("") || idiomaDest.trim().equals("") || jListDestinoInt.isSelectionEmpty()) {
            this.mostrarError("Seleccione un elemento de la lista para eliminar.");
            return;
        } else {
            jDialogEliminar.setVisible(true);
            if (eliminar) {
                try {
                    ControladorTraductorInterno.eliminar(selectedFactory, textoOrigen, idiomaOrig, textoDestInt, idiomaDest);
                    this.jButtonTraducirActionPerformed(evt);
                    this.mostrarExito("Traducción eliminada correctamente.");
                } catch (ExcepcionConexionError ex) {
                    this.mostrarError(ex.getMessage());
                } catch (ExcepcionDataBaseError ex) {
                    this.mostrarError(ex.getMessage());
                }
            }
        }
    }//GEN-LAST:event_jButtonEliminarActionPerformed

    private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed
        eliminar = true;
        this.jButtonEliminarActionPerformed(evt);
        eliminar = false;
        jDialogEliminar.setVisible(false);

    }//GEN-LAST:event_jButtonAceptarActionPerformed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        eliminar = false;
        jDialogEliminar.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    private void jButtonActualizarVerTextoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonActualizarVerTextoActionPerformed
        this.actualizarValores();
        if (textoOrigen.trim().equals("") || jTextAreaVerTexto.getText().trim().equalsIgnoreCase("")) {
            this.mostrarError("Ingrese una traducción en el cuadro de texto.");
            return;
        } else {
            try {
                jPanel1.setEnabled(false);
                String textoDestinoNew = jTextAreaVerTexto.getText();
                String textoDestinoOld = textoDestInt;
                ControladorTraductorInterno.modificar(selectedFactory, textoOrigen, idiomaOrig, textoDestinoNew, textoDestinoOld, idiomaDest);
                this.jButtonTraducirActionPerformed(evt);
                this.mostrarExito("Traducción modificada correctamente.");
            } catch (ExcepcionConexionError ex) {
                this.mostrarError(ex.getMessage());
            } catch (ExcepcionDataBaseError ex) {
                this.mostrarError(ex.getMessage());
            } finally {
                jFrameVerTexto.setVisible(false);
                jPanel1.setEnabled(true);
            }
        }
    }//GEN-LAST:event_jButtonActualizarVerTextoActionPerformed

    private void jButtonCerrarVerTextoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCerrarVerTextoActionPerformed
        jFrameVerTexto.setVisible(false);
    }//GEN-LAST:event_jButtonCerrarVerTextoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new JFrameMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAceptar;
    private javax.swing.JButton jButtonActualizar;
    private javax.swing.JButton jButtonActualizarVerTexto;
    private javax.swing.JButton jButtonAgregar;
    private javax.swing.JButton jButtonCambio;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonCerrarVerTexto;
    private javax.swing.JButton jButtonEliminar;
    private javax.swing.JButton jButtonTraducir;
    private javax.swing.JButton jButtonVerTexto;
    private javax.swing.JComboBox jComboBoxDB;
    private javax.swing.JComboBox jComboBoxIdiomaDestino;
    private javax.swing.JComboBox jComboBoxIdiomaOrigen;
    private javax.swing.JComboBox jComboBoxServicio;
    private javax.swing.JDialog jDialogEliminar;
    private javax.swing.JFrame jFrameCaratula;
    private javax.swing.JFrame jFrameVerTexto;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelCaratula;
    private javax.swing.JLabel jLabelDB;
    private javax.swing.JLabel jLabelEliminar;
    private javax.swing.JLabel jLabelMensajes;
    private javax.swing.JLabel jLabelTraductor;
    private javax.swing.JList jListDestinoInt;
    private javax.swing.JMenu jMenuArchivo;
    private javax.swing.JMenu jMenuAyuda;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItemAcercaDe;
    private javax.swing.JMenuItem jMenuItemSalir;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelCaratula;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JTextArea jTextAreaDestinoExt;
    private javax.swing.JTextArea jTextAreaOrigen;
    private javax.swing.JTextArea jTextAreaVerTexto;
    // End of variables declaration//GEN-END:variables

    private void initComboBox() {
        final TreeSet<String> valuesServicios = new TreeSet<String>(servicios.keySet());
        modelServicios = new DefaultComboBoxModel(valuesServicios.toArray());
        jComboBoxServicio.setModel(modelServicios);

        idServicio = jComboBoxServicio.getSelectedItem().toString();
        unServicio = servicios.get(idServicio);

        final Map<String, IdiomaDTO> idiomas = unServicio.getIdiomas();
        TreeSet<String> valuesIdiomas = new TreeSet<String>(idiomas.keySet());//Claves del Map que son los valores para los ComboBox
        modelIdiomasOrigen = new DefaultComboBoxModel(valuesIdiomas.toArray());
        modelIdiomasDestino = new DefaultComboBoxModel(valuesIdiomas.toArray());
        jComboBoxIdiomaOrigen.setModel(modelIdiomasOrigen);
        jComboBoxIdiomaDestino.setModel(modelIdiomasDestino);

        modelDB = new DefaultComboBoxModel();
        for (DAOFactory fact : factorias) {
            modelDB.addElement(fact);
        }
        jComboBoxDB.setModel(modelDB);
    }

    /**
     * Inicializa por defecto los componentes.
     */
    private void setDefaultComponentes() {
        //TODO: leer de log.
        jComboBoxDB.setSelectedItem(factorias.get(1));//0=Derby;1=Postgres;2=MySQL
        jComboBoxServicio.setSelectedItem("Google");
        jComboBoxIdiomaOrigen.setSelectedItem("Español");
        jComboBoxIdiomaDestino.setSelectedItem("Deutsch");
    }

    private String getIdiomaComboBoxServ(JComboBox unJComboBox) {
        String item = unJComboBox.getSelectedItem().toString();
        HashMap<String, IdiomaDTO> idiomas = unServicio.getIdiomas();
        return idiomas.get(item).getSigla();
    }

    private void setImagenes() {

        jMenuArchivo.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/logo1.png")));
        jMenuAyuda.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/help2.png")));
        jLabelCaratula.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/Caratula Trabajo Final Taller de Programacion.JPG")));
        jMenuItemSalir.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/cancel.png")));
        jMenuItemAcercaDe.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/info.png")));
        jLabelDB.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/database_go.png")));
        jLabelTraductor.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/server_go.png")));
        jButtonCambio.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/arrow_refresh.png")));
        jButtonTraducir.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/bullet_go.png")));
        jButtonAgregar.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/database_save.png")));
        jButtonActualizar.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/page_edit.png")));
        jButtonActualizarVerTexto.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/page_edit.png")));
        jButtonVerTexto.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/magnifier.png")));
        jButtonEliminar.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/delete.png")));
        jButtonCerrarVerTexto.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/cancel.png")));
    }

    private void limpiarElementos() {
        jTextAreaDestinoExt.setText("");
        modelListaResultados = new DefaultComboBoxModel();
        jListDestinoInt.setModel(modelListaResultados);
        jTextAreaDestinoExt.setBackground(Color.WHITE);
        jLabelMensajes.setIcon(null);
        jLabelMensajes.setText("");
    }

    private void actualizarValores() {
        selectedFactory = (DAOFactory) jComboBoxDB.getModel().getSelectedItem();
        idServicio = jComboBoxServicio.getSelectedItem().toString();
        textoOrigen = this.formatString(jTextAreaOrigen.getText());
        idiomaOrig = getIdiomaComboBoxServ(jComboBoxIdiomaOrigen);
        textoDestExt = this.formatString(jTextAreaDestinoExt.getText());
        idiomaDest = getIdiomaComboBoxServ(jComboBoxIdiomaDestino);
        if (!jListDestinoInt.isSelectionEmpty()) {
            String textoCrudo = jListDestinoInt.getSelectedValue().toString();
            textoDestInt = this.formatString(textoCrudo);
        }
    }

    private String formatString(String texto) {
        if (texto.length() > 0) {
            //Elimina tags de color en el texto.
            for (int i = 0; i < texto.length(); i++) {
                int inicioA = texto.indexOf("<");
                int finA = texto.indexOf(">");
                if (finA != -1 && inicioA == 0) {
                    texto = texto.substring(finA + 1, texto.length());
                }
                if (finA != -1 && inicioA > 1) {
                    texto = texto.substring(0, inicioA);
                }
            }
            //Elimina espacios entre los textos.
            String[] subTextos = texto.split(" ");//Divide 'textos' donde hay espacios.
            String listaTexto = "";
            for (String splitTexto : subTextos) {
                for (int t = 0; t < splitTexto.length(); t++) {
                    if (splitTexto.charAt(0) == ' ') {//si la primer parte contiene un espacio.
                        splitTexto = splitTexto.substring(1, splitTexto.length());
                    }
                    if (splitTexto.charAt(splitTexto.length() - 1) == ' ') {//si la ultima contiene un espacio.
                        splitTexto = splitTexto.substring(0, splitTexto.length() - 1);
                    }
                }
                if (splitTexto.length() > 0) {
                    listaTexto += splitTexto + " ";
                }
            }
            if (listaTexto.length() == 1) {
                texto = "";
            }
            if (listaTexto.length() > 1) {
                texto = listaTexto.substring(0, listaTexto.length() - 1);//Elimina el ultimo espació de las concatenaciones.
            }
        }
        return texto;
    }

    private ArrayList<String> colorTexto(ArrayList<String> listaTexto, String color) {
        ArrayList<String> textos = new ArrayList<String>();
        for (Iterator<String> it = listaTexto.iterator(); it.hasNext();) {
            String unTexto = it.next();
            textos.add("<html><FONT COLOR= \"" + color + "\">" + unTexto + "</FONT></html>");
        }
        return textos;
    }

    private void setFuente(String fuenteTextos, int estiloTextos, int tamTextos) {
        jTextAreaOrigen.setFont(new java.awt.Font(fuenteTextos, estiloTextos, tamTextos));
        jTextAreaDestinoExt.setFont(new java.awt.Font(fuenteTextos, estiloTextos, tamTextos));
        jListDestinoInt.setFont(new java.awt.Font(fuenteTextos, estiloTextos, tamTextos));
        jTextAreaVerTexto.setFont(new java.awt.Font(fuenteTextos, estiloTextos, tamTextos));
    }

    private void mostrarError(String error) {
        System.out.println(error);
        jLabelMensajes.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/exclamation.png")));
        jLabelMensajes.setText(error);
        Toolkit.getDefaultToolkit().beep();
        //TODO: Guardar en log.
    }

    private void mostrarExito(String error) {
        jLabelMensajes.setIcon(new ImageIcon(getClass().getResource("/GUI/iconos/accept.png")));
        jLabelMensajes.setText(error);
        System.out.println(error);
        //TODO: Guardar en log.
    }
}

